/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for MenuAdminsDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class MenuAdminsDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public MenuAdminsDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion


       
        #region Public Methods
        public int Insert(MenuAdminsDO objMenuAdminsDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMenuAdmins_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Name", SqlDbType.NVarChar);
            Sqlparam.Value = objMenuAdminsDO.Name;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Link", SqlDbType.NVarChar);
            Sqlparam.Value = objMenuAdminsDO.Link;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Title", SqlDbType.NVarChar);
            Sqlparam.Value = objMenuAdminsDO.Title;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@UserType", SqlDbType.Int);
            Sqlparam.Value = objMenuAdminsDO.UserType;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Level", SqlDbType.NVarChar);
            Sqlparam.Value = objMenuAdminsDO.Level;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Order", SqlDbType.Int);
            Sqlparam.Value = objMenuAdminsDO.Order;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ParentID", SqlDbType.Int);
            Sqlparam.Value = objMenuAdminsDO.ParentID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(MenuAdminsDO objMenuAdminsDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMenuAdmins_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@MenuAdminID", SqlDbType.Int);
            Sqlparam.Value = objMenuAdminsDO.MenuAdminID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Name", SqlDbType.NVarChar);
            Sqlparam.Value = objMenuAdminsDO.Name;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Link", SqlDbType.NVarChar);
            Sqlparam.Value = objMenuAdminsDO.Link;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Title", SqlDbType.NVarChar);
            Sqlparam.Value = objMenuAdminsDO.Title;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@UserType", SqlDbType.Int);
            Sqlparam.Value = objMenuAdminsDO.UserType;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Level", SqlDbType.NVarChar);
            Sqlparam.Value = objMenuAdminsDO.Level;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Order", SqlDbType.Int);
            Sqlparam.Value = objMenuAdminsDO.Order;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ParentID", SqlDbType.Int);
            Sqlparam.Value = objMenuAdminsDO.ParentID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(MenuAdminsDO objMenuAdminsDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMenuAdmins_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@MenuAdminID", SqlDbType.Int);
            Sqlparam.Value = objMenuAdminsDO.MenuAdminID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMenuAdmins_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public MenuAdminsDO Select(MenuAdminsDO objMenuAdminsDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMenuAdmins_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@MenuAdminID", SqlDbType.Int);
            Sqlparam.Value = objMenuAdminsDO.MenuAdminID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["MenuAdminID"]))
                    objMenuAdminsDO.MenuAdminID = Convert.ToInt32(dr["MenuAdminID"]);
                if (!Convert.IsDBNull(dr["Name"]))
                    objMenuAdminsDO.Name = Convert.ToString(dr["Name"]);
                if (!Convert.IsDBNull(dr["Link"]))
                    objMenuAdminsDO.Link = Convert.ToString(dr["Link"]);
                if (!Convert.IsDBNull(dr["Title"]))
                    objMenuAdminsDO.Title = Convert.ToString(dr["Title"]);
                if (!Convert.IsDBNull(dr["UserType"]))
                    objMenuAdminsDO.UserType = Convert.ToInt32(dr["UserType"]);
                if (!Convert.IsDBNull(dr["Level"]))
                    objMenuAdminsDO.Level = Convert.ToString(dr["Level"]);
                if (!Convert.IsDBNull(dr["Order"]))
                    objMenuAdminsDO.Order = Convert.ToInt32(dr["Order"]);
                if (!Convert.IsDBNull(dr["ParentID"]))
                    objMenuAdminsDO.ParentID = Convert.ToInt32(dr["ParentID"]);

            }
            return objMenuAdminsDO;
        }

        public DataTable SelectGetByTop(string Top, string Where, string Order)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMenuAdmin_GetByTop";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Top", SqlDbType.NVarChar);
            Sqlparam.Value = Top;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Where", SqlDbType.NVarChar);
            Sqlparam.Value = Where;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Order", SqlDbType.NVarChar);
            Sqlparam.Value = Order;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMenuAdmins_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrMenuAdminsDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    MenuAdminsDO objMenuAdminsDO = new MenuAdminsDO();
                    if (!Convert.IsDBNull(dr["MenuAdminID"]))
                        objMenuAdminsDO.MenuAdminID = Convert.ToInt32(dr["MenuAdminID"]);
                    if (!Convert.IsDBNull(dr["Name"]))
                        objMenuAdminsDO.Name = Convert.ToString(dr["Name"]);
                    if (!Convert.IsDBNull(dr["Link"]))
                        objMenuAdminsDO.Link = Convert.ToString(dr["Link"]);
                    if (!Convert.IsDBNull(dr["Title"]))
                        objMenuAdminsDO.Title = Convert.ToString(dr["Title"]);
                    if (!Convert.IsDBNull(dr["UserType"]))
                        objMenuAdminsDO.UserType = Convert.ToInt32(dr["UserType"]);
                    if (!Convert.IsDBNull(dr["Level"]))
                        objMenuAdminsDO.Level = Convert.ToString(dr["Level"]);
                    if (!Convert.IsDBNull(dr["Order"]))
                        objMenuAdminsDO.Order = Convert.ToInt32(dr["Order"]);
                    if (!Convert.IsDBNull(dr["ParentID"]))
                        objMenuAdminsDO.ParentID = Convert.ToInt32(dr["ParentID"]);
                    arrMenuAdminsDO.Add(objMenuAdminsDO);
                }
            }
            return arrMenuAdminsDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMenuAdmins_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectMaxId(string where)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spMenuAdmins_GetMaxId";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@where", SqlDbType.NVarChar);
            Sqlparam.Value = where;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        #endregion

    }

}
